//
//  LaomiRequestModel.m
//  LaomiKit
//
//  Created by laomi on 2020/7/16.
//  Copyright © 2020 laomi. All rights reserved.
//

#import "LaomiRequestModel.h"
NSString *const CPUserInfoStoreKey = @"CP_UserInfoStoreKey";
@implementation LaomiRequestModel

-(instancetype)init
{
    self = [super init];
    if (self) {
        [LaomiRequestModel setupDefaultValue:self];
    }
    return self;;
}

+(LaomiRequestModel*)initWith:(NSString*)url param:(NSDictionary*)param;
{
    LaomiRequestModel *model = [[LaomiRequestModel alloc]init];
    model.url = url;
    model.param = param;
    [self setupDefaultValue:model];
    return model;
}
+(void)setupDefaultValue:(LaomiRequestModel*)model
{
    model.header = @{};
    model.loadingString = @"loading...";
    model.networkErrorString = @"网络错误";
    model.method = @"POST";
    model.SUCCESS_CODE = http_success_code;
    model.EXPIRE_CODE = request_login_expire;
    model.request_data_key = request_data_key;
    model.request_status_key = request_status_key;
    NSDictionary *dict = [[NSUserDefaults standardUserDefaults]objectForKey:CPUserInfoStoreKey];
    model.header = @{@"Authorization":dict[@"token"]?dict[@"token"]:@""};
    __weak typeof(model) weakModel = model;
    model.expireBlock = ^(id  _Nullable obj) {
        [[NSNotificationCenter defaultCenter] postNotificationName:request_login_expire_notification object:weakModel];
    };
}
@end
